<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>进度条</title>
</head>
<body>
    <div class="box">
        <div id="jingdutiao" style="width: 0px;"> </div>
        <span id="num">0%</span>
    </div>
    <style>
        .box{
            width: 800px;
            height: 50px;
            border-radius: 4px;
            margin: 100px auto;
            border: 2px solid blue;
            position: relative;
        
        }
        #jingdutiao{
            height: 50px;
            background: yellow;
            border-radius: 4px;
            float: left;
            background-image: linear-gradient(to right, red , yellow,blue,pink,black);
            /* 径向渐变从右边到左 */
            /* background-image: repeating-radial-gradient(red, yellow,blue,pink 10%); */
            /* 径向渐变由中心到四周 */
        }

        #num{
            position: absolute;
            transform: translateY(-50%);
            top:50%;
            left: 5px;
        }
    </style>
    <script>
        // 需要通过定时器去改变进度条宽度，并且需要用定时器
        var timer=setInterval(function(){
            // 每执行一次定时器，将在进度条原来的宽度上面添加+10
            var style=parseInt(jingdutiao.style.width);
            var curStyle=style+13;
            if(curStyle>=800){
                curStyle=800;
                clearInterval(timer)
                // 在原来的基础上面+10，在赋值给元素的宽度
            }
            jingdutiao.style.width=curStyle+'px';
            // 给数字的元素添加left，根据进度条的变化而变化
            num.style.left=curStyle+2+'px';
            num.innerHTML=((curStyle/800)*100).toFixed(2)+'%';
// tofixed(2)表示保留两位小数点
        },100)
    </script>

    
</body>
</html>